package com.atguigu.common.exception;

/**
 * @author liuying
 * @date 2022/10/11
 */

import com.atguigu.common.result.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 自定义异常类  设置了自定义异常再有运行时异常直接在枚举类中定义类型，
 * 然后拿BusinessException.类型就可
 */
@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException{

    //错误码
    private Integer code;

    //错误信息
    private String message;

    /**
     * @param message 错误消息
     */
    public BusinessException(String message){
        this.message = message;
    }

    /**
     * @param code     错误码
     * @param message  错误消息
     */
    public BusinessException(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    /**
     * @param code    错误码
     * @param message 错误消息
     * @param cause   原始异常对象
     */
    public BusinessException(Integer code,String message,Throwable cause){
        super(cause);
        this.code = code;
        this.message = message;
    }

    /**
     * @param resultCodeEnum 接收枚举类型
     */
    public BusinessException(ResponseEnum resultCodeEnum){
        this.message = resultCodeEnum.getMessage();
        this.code = resultCodeEnum.getCode();
    }

    /**
     *
     * @param resultCodeEnum 接收枚举类型
     * @param cause  原始异常对象
     */
    public BusinessException(ResponseEnum resultCodeEnum,Throwable cause){
        super(cause);
        this.message = resultCodeEnum.getMessage();
        this.code = resultCodeEnum.getCode();
    }
}
